/***
 * * PROJECT
 * *    ATaG
 * * VERSION
 * *    $Revision: 1.2 $
 * * DATE
 * *    $Date: 2007/06/09 07:15:49 $
 * * LOG
 * *    $Log: ATaGTaskDeclaration.java,v $
 * *    Revision 1.2  2007/06/09 07:15:49  animesh
 * *    update after fixing all but sets and serialization.
 * *
 * *
 * *    Revision 1.12  2007/5/17 14:10:00  qunzhi
 * *    Replaced generics
 * *
 * *    Revision 1.11  2006/12/30 09:35:27  animesh
 * *    Added init code for neededAttribute. Should be null'd in the constructor.
 * *
 * *    Revision 1.10  2006/12/19 02:18:08  animesh
 * *    added INSTANTIATION_REGION_PER_INSTANCE
 * *
 * *    Revision 1.9  2006/11/03 23:09:36  lmottola
 * *    Changed nodeAttributes package.
 * *
 * *    Revision 1.8  2006/11/03 23:08:18  lmottola
 * *    Traffic application beta running.
 * *
 * *    Revision 1.7  2006/10/30 23:54:57  animesh
 * *    neededAttribute and its get/set methods added. Predicate removed as it was not relevant.
 * *
 * *    Revision 1.6  2006/10/28 11:14:58  animesh
 * *    added regionID and regionLabel
 * *
 * *    Revision 1.5  2006/10/27 23:19:54  animesh
 * *    changed LNScope to LNPredicate
 * *
 * *    Revision 1.4  2006/10/26 22:25:37  animesh
 * *    added "slash", "at" and "instScope"
 * *
 * *    Revision 1.3  2006/10/19 22:18:11  animesh
 * *    *** empty log message ***
 * *
 * *    Revision 1.2  2006/10/19 21:21:53  lmottola
 * *    Added CVS preamble.
 * *
 * *
 * *   ATaG (Abstract Task Graph) - Data-driven Macroprogramming for
 * *                                Sensor Networks
 * *
 * *   This program is free software; you can redistribute it and/or
 * *   modify it under the terms of the GNU General Public License
 * *   as published by the Free Software Foundation; either version 2
 * *   of the License, or (at your option) any later version.
 * *
 * *   This program is distributed in the hope that it will be useful,
 * *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 * *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * *   GNU General Public License for more details.
 * *
 * *   You should have received a copy of the GNU General Public License
 * *   along with this program; if not, you may find a copy at the FSF web
 * *   site at 'www.gnu.org' or 'www.fsf.org', or you may write to the
 * *   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * *   Boston, MA  02111-1307, USA
 ***/

package atag.common;

import atag.runtime.ln.nodeAttributes.NodeAttribute;
import atag.runtime.ln.neighborhoodDefs.Predicate;
//import java.util.ArrayList;
import java.util.Vector;



/**
 *
 * @author Animesh [heavily inspired by Amol's work]
 */
public class ATaGTaskDeclaration {
    
    public static final int INVALID = 0x0;
    
    // firing rules
    public static final int FIRING_PERIODIC = 0x1;
    public static final int FIRING_ANYDATA = 0x2;
    public static final int FIRING_ALLDATA = 0x4;
    public static final int FIRING_TRIGGERED = 0x8;
    
    //instantiation rules
    public static final int INSTANTIATION_ONE_ANYWHERE = 0x1;
    public static final int INSTANTIATION_ONE_ON_NODE_ID = 0x2;
    // following used for absolute numbers [on exactly 7 nodes]
    public static final int INSTANTIATION_NODES_PER_INSTANCE = 0x4;
    // follwing one used for nodes-per-instance:/4 [on 1/4 of the nodes]
    // or should we use the slash?    
    public static final int INSTANTIATION_NODES_PER_INSTANCE_FRACTIONAL = 0x8;
    /** used for one-per-region*/
    public static final int INSTANTIATION_PARTITION_PER_INSTANCE = 0x10;

	public static final String ABILITY_ATTRIBUTE_NAME = "Ability";

    /** name of task*/
    private String name;
    
    /** array of two items, second item relevent only in some cases
     */
    private int[] firingRule; 
    /** array of two items, second item relevent only in some cases
     */
    private int[] location; 

    /**
     * unique ID. To be set during sanitization of code [checking for dupes etc.]
     */
    private int ID;
    
    /**
     * Array of data items to be consumed
     */
    //private ArrayList<String> inDataNames;
    private Vector inDataNames;
    
    /**
     * Array of data items to be output
     */
    //private ArrayList<String> outDataNames;
    private Vector outDataNames;
    
    /**
     * priority of the task
     */
    private int priority;

    /**
     * instantiation parameter -- dunno what this is
     */
    private int instParam;
    /**
     * Instantiation type - No idea what this is either
     */
    private String instType;
    
    /**
     * Should I run at init?
     */
    private boolean runAtInit;
    
    /*
     * List of nodes this task is assigned to
     */
    //private ArrayList<Integer> assignedTo;
    private Vector assignedTo;
    
    
    /** flag to indicate if there is a "slash" in the instantiation */
    private boolean slash;
    
    /** flag to indicate if there is a "@" in the instantiation */
    private boolean at;
    
    /** The logical neighborhood scope, if used in the instantiation*/
    private NodeAttribute neededAttribute;

    /** For region names such as "HS"*/
    private String myRegionName;

    /** For region labels such as "1"*/
    private int myRegionID;
    
    /**
     * Creates a new instance of ATaGTaskDeclaration
     */
    public ATaGTaskDeclaration() {
        //this.inDataNames = new ArrayList<String>();
        //this.outDataNames = new ArrayList<String>();
        //this.assignedTo = new ArrayList<Integer>();
        this.inDataNames = new Vector();
        this.outDataNames = new Vector();
        this.assignedTo = new Vector();
        this.myRegionName = new String();
        this.neededAttribute = null;
    }
    
    public String getName(){
        return this.name;
    }
    
    public void setName(String newName){
        this.name = new String(newName);
    }
    
    public int[] getFiringRule(){
        return this.firingRule;
    }

    public int[] getLocation(){
        return this.location;
    }

    public void setFiringRule(int[] newFiringRule){
        this.firingRule = newFiringRule;
    }

    public void setLocation(int[] newLocation){
        this.location = newLocation;
    }

    public int getID() {
        return this.ID;
    }

    public void setID(int newID) {
        this.ID = newID;
    }

    public int getPriority() {
        return this.priority;
    }

    public void setPriority(int newPriority) {
        this.priority = newPriority;
    }

    public int getInstParam() {
        //return this.instParam;
        return this.location[1];
    }

    public void setInstParam(int newInstParam) {
        this.instParam = newInstParam;
    }

    public String getInstType() {
        //TODO change this to a string version of the instantiation rule
        return this.instType;        
    }

    public void setInstType(String newInstType) {
        this.instType = new String(newInstType);
    }

    public boolean getRunAtInit() {
        return this.runAtInit;
    }

    public void setRunAtInit(boolean newRunAtInit) {
        this.runAtInit = newRunAtInit;
    }

    
    //public ArrayList<String> inDataNames() {
    public Vector inDataNames() {
        return this.inDataNames;
    }

    //public ArrayList<String> outDataNames() {
    public Vector outDataNames() {
        return this.outDataNames;
    }

    public void assign(int node) {
        assignedTo.addElement(new Integer(node));
    }

    /**
     * -- not really used.
     */
    //public ArrayList<Integer> getAssignedTo() {
    public Vector getAssignedTo() {
        return this.assignedTo;
    }

/**  
 * @returns the assignedTo ArrayList inthe form of an integer array
 */
    public int[] assignment() {
        int arraySize = this.assignedTo.size();
        int[] retArr = new int[arraySize];
        
        for (int i=0; i<arraySize ; i++)
            retArr[i] = ((Integer) this.assignedTo.elementAt(i)).intValue();
        
        return retArr;
        
    }

    public boolean getSlash() {
        return this.slash;
    }

    public void setSlash(boolean newSlash) {
        this.slash = newSlash;
    }
    
    
    public boolean getAt() {
        return this.at;
    }

    public void setAt (boolean newAt) {
        this.at = newAt;
    }    
    
    public NodeAttribute getNeededAttribute(){
        return this.neededAttribute;
    }
    
    public void setNeededAttribute(NodeAttribute newAttribute){
        this.neededAttribute = newAttribute;
    }
    
    public String getMyRegionName(){
        return this.myRegionName;
    }
    
    public void setMyRegionName(String newName){
        this.myRegionName = new String(newName);
    }
    
    public int getMyRegionID(){
        return this.myRegionID;
    }
    
    public void setMyRegionID(int newID){
        this.myRegionID = newID;
    }
}
